<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"
      xmlns:f="http://java.sun.com/jsf/core"
      xmlns:h="http://java.sun.com/jsf/html"
      xmlns:ui="http://java.sun.com/jsf/facelets"
      xmlns:p="http://primefaces.org/ui">
<ui:composition template="../templates/layout.xhtml">
    <ui:define name="content">
        <p:growl id="messages" showDetail="false" />
        <h:form id="listForm" prependId="false" enctype="multipart/form-data">
        	 
            <p:panel id="data" header="Purchases">
                <h:outputFormat id="noRecordsFound" value="#{messages.label_no_records_found}" rendered="#{!purchasesBean.dataVisible}">
                   <f:param value="Purchases" />
                </h:outputFormat>
                
                <p:dataTable id="list" value="#{purchasesBean.allPurchases}" var="purchase" rendered="#{purchasesBean.dataVisible}" resizableColumns="false" paginator="false" paginatorTemplate=" {CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}" rowsPerPageTemplate="5,10,25,50" rows="10">
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Purchase Id" />
                        </f:facet>
                        <h:outputText value="#{purchase.purchaseId}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Product Code" />
                        </f:facet>
                        <h:outputText value="#{purchase.product.code}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Batch No" />
                        </f:facet>
                        <h:outputText value="#{purchase.batchNo}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Purcahse Date" />
                        </f:facet>
                        <h:outputText value="#{purchase.purcahseDate}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Product" />
                        </f:facet>
                        <h:outputText value="#{purchase.product.narrative}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Cotton Units" />
                        </f:facet>
                        <h:outputText value="#{purchase.cottonUnits}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Cotton" />
                        </f:facet>
                        <h:outputText value="#{purchase.cotton}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Dozen" />
                        </f:facet>
                        <h:outputText value="#{purchase.dozon}" />
                    </p:column>
                    
                    <p:column style="text-align: center;">
                    	<f:facet name="header">
                            <h:outputText value="Units" />
                        </f:facet>
                        <h:outputText value="#{purchase.units}" />
                    </p:column>
                    
                    
                    <p:column styleClass="action-column">
                        <f:facet name="header">
                            <h:outputText value="Actions" />
                        </f:facet>
                        
                        <p:commandButton id="editButton" icon="ui-icon-pencil" showEffect="fade" hideEffect="fade" oncomplete="editDialog.show()"  update=":editDialog"  title="#{messages.label_edit}">
                            <f:setPropertyActionListener value="#{purchase}" target="#{purchasesBean.selectedPurchase}" />
                            <f:setPropertyActionListener value="#{purchase.product.productType.productCatagory.catagoryId}" target="#{purchasesBean.selectedProductCat}" />
                            <f:setPropertyActionListener value="#{purchase.product.productType.typeId}" target="#{purchasesBean.selectedProductType}" />
                            <f:setPropertyActionListener value="#{purchase.product.productId}" target="#{purchasesBean.selectedProduct}" />
                        </p:commandButton>
                        <p:tooltip for="editButton" value="#{messages.label_edit}" showEffect="fade" hideEffect="fade" />
                        <p:commandButton id="deleteButton" icon="ui-icon-trash" oncomplete="deleteDialog.show()" title="#{messages.label_delete}" >
                            <f:setPropertyActionListener value="#{purchase}" target="#{purchasesBean.selectedPurchase}" />
                            
                        </p:commandButton>
                        <p:tooltip for="deleteButton" value="#{messages.label_delete}" showEffect="fade" hideEffect="fade" />
                    </p:column>
                    
                </p:dataTable>
                
                <p:commandButton value="#{messages.label_create} Purchases" onclick="saveDialog.show()" type="button" />
                <h:commandLink>  
		            <h:graphicImage library="images" name="excel.png" />
		            <p:dataExporter type="xls" target="list" fileName="Purchases" />  
        		</h:commandLink>
        		<h:commandLink>  
		            <h:graphicImage library="images" name="pdf.png" />
		            <p:dataExporter type="pdf" target="list" fileName="Purchases" />  
        		</h:commandLink>
            </p:panel>
        </h:form>
       
        <p:dialog id="saveDialog" header="#{messages.label_save} Purchases" modal="true" widgetVar="saveDialog" resizable="true" maximizable="true" showEffect="fade" hideEffect="fade">
            <h:form id="saveForm" enctype="multipart/form-data">
                <h:panelGrid id="savePanelGrid" columns="3" styleClass="dialog" columnClasses="col1,col2,col3" >
                	
                	<h:outputText id="productCatOutput" value="Product Category: * " />
                	<p:selectOneMenu id="productCatMenu" effect="fade" style="width:200px" required="true" value="#{purchasesBean.selectedProductCat}">
                		<f:ajax event="change" render=":saveForm:productTypeMenu" listener="#{purchasesBean.loadProductTypeCMB}"/>
                		<f:selectItems var="cmb" itemLabel="#{cmb.label}" itemValue="#{cmb.value}" value="#{purchasesBean.productCatComboList}" />
                	</p:selectOneMenu>
	             	<p:message id="productCatMessage" for="productCatMenu" display="icon"/>
	             	
	             	<h:outputText id="productTypeOutput" value="Product Type: * " />
                	<p:selectOneMenu id="productTypeMenu" effect="fade" style="width:200px" required="true" value="#{purchasesBean.selectedProductType}">
                		<f:ajax event="change" render=":saveForm:productMenu" listener="#{purchasesBean.loadProductCMB}"/>
                		<f:selectItems var="cmb" itemLabel="#{cmb.label}" itemValue="#{cmb.value}" value="#{purchasesBean.productTypeComboList}" />
                	</p:selectOneMenu>
	             	<p:message id="productTypeMessage" for="productTypeMenu" display="icon"/>
	             	
	             	<h:outputText id="productOutput" value="Product: * " />
                	<p:selectOneMenu id="productMenu" effect="fade" style="width:200px" required="true" value="#{purchasesBean.selectedProduct}">
                		<f:selectItems var="cmb" itemLabel="#{cmb.label}" itemValue="#{cmb.value}" value="#{purchasesBean.productComboList}" />
                	</p:selectOneMenu>
	             	<p:message id="productMessage" for="productMenu" display="icon"/>
	                
	                <h:outputText id="dateOutputCal" value="Date: * " />
	                <p:calendar value="#{purchasesBean.newPurchase.purcahseDate}" id="dateButtonCal" showOn="button" required="true" />
	                <p:message id="dateButtonCalMessage" for="dateButtonCal" display="icon"/>
	                
	                <h:outputText id="cottonOutput" value="Cottons: * " />
	                <p:inputText id="cottonInput" required="true" value="#{purchasesBean.newPurchase.cotton}"/>
	                <p:message id="cottoneMessage" for="cottonInput" display="icon"/>
	                
	                <h:outputText id="dozonOutput" value="Dozen: * " />
	                <p:inputText id="dozonInput" required="true" value="#{purchasesBean.newPurchase.dozon}"/>
	                <p:message id="dozoneMessage" for="dozonInput" display="icon"/>
	                
	                <h:outputText id="unitOutput" value="Units: * " />
	                <p:inputText id="unitInput" required="true" value="#{purchasesBean.newPurchase.units}"/>
	                <p:message id="uniteMessage" for="unitInput" display="icon"/>
	                
	                <p:commandButton value="#{messages.label_save}" action="#{purchasesBean.saveNewPurchase}" update=":saveDialog :editDialog :listForm:data" oncomplete="saveDialog.hide()" />
	                <p:commandButton value="#{messages.label_close}" onclick="saveDialog.hide()" type="button" />
                </h:panelGrid>
                
            </h:form>
        </p:dialog>
        
       
        <p:dialog id="editDialog" header="#{messages.label_edit} Purchases" modal="true" widgetVar="editDialog" resizable="true" maximizable="true" showEffect="fade" hideEffect="fade">
            <h:form id="editForm" enctype="multipart/form-data">
                <h:panelGrid id="editPanelGrid" columns="3" styleClass="dialog" columnClasses="col1,col2,col3" >
                	
                	<h:outputText id="productCatOutput" value="Product Category: * " />
                	<p:selectOneMenu id="productCatMenu" effect="fade" style="width:200px" required="true" value="#{purchasesBean.selectedProductCat}">
                		<f:ajax event="change" render=":editForm:productTypeMenu" listener="#{purchasesBean.loadProductTypeCMB}"/>
                		<f:selectItems var="cmb" itemLabel="#{cmb.label}" itemValue="#{cmb.value}" value="#{purchasesBean.productCatComboList}" />
                	</p:selectOneMenu>
	             	<p:message id="productCatMessage" for="productCatMenu" display="icon"/>
	             	
	             	<h:outputText id="productTypeOutput" value="Product Type: * " />
                	<p:selectOneMenu id="productTypeMenu" effect="fade" style="width:200px" required="true" value="#{purchasesBean.selectedProductType}">
                		<f:ajax event="change" render=":editForm:productMenu" listener="#{purchasesBean.loadProductCMB}"/>
                		<f:selectItems var="cmb" itemLabel="#{cmb.label}" itemValue="#{cmb.value}" value="#{purchasesBean.productTypeComboList}" />
                	</p:selectOneMenu>
	             	<p:message id="productTypeMessage" for="productTypeMenu" display="icon"/>
	             	
	             	<h:outputText id="productOutput" value="Product: * " />
                	<p:selectOneMenu id="productMenu" effect="fade" style="width:200px" required="true" value="#{purchasesBean.selectedProduct}">
                		<f:selectItems var="cmb" itemLabel="#{cmb.label}" itemValue="#{cmb.value}" value="#{purchasesBean.productComboList}" />
                	</p:selectOneMenu>
	             	<p:message id="productMessage" for="productMenu" display="icon"/>
	                
	                <h:outputText id="dateOutputCal" value="Date: * " />
	                <p:calendar value="#{purchasesBean.selectedPurchase.purcahseDate}" id="dateButtonCal" showOn="button" required="true" />
	                <p:message id="dateButtonCalMessage" for="dateButtonCal" display="icon"/>
	                
	                <h:outputText id="cottonOutput" value="Cottons: * " />
	                <p:inputText id="cottonInput" required="true" value="#{purchasesBean.selectedPurchase.cotton}"/>
	                <p:message id="cottoneMessage" for="cottonInput" display="icon"/>
	                
	                <h:outputText id="dozonOutput" value="Dozen: * " />
	                <p:inputText id="dozonInput" required="true" value="#{purchasesBean.selectedPurchase.dozon}"/>
	                <p:message id="dozoneMessage" for="dozonInput" display="icon"/>
	                
	                <h:outputText id="unitOutput" value="Units: * " />
	                <p:inputText id="unitInput" required="true" value="#{purchasesBean.selectedPurchase.units}"/>
	                <p:message id="uniteMessage" for="unitInput" display="icon"/>
	                
	                <p:commandButton value="#{messages.label_update}" action="#{purchasesBean.updatePurchase}" update=":saveDialog :editDialog :listForm:data" oncomplete="editDialog.hide()" />
	                <p:commandButton value="#{messages.label_close}" onclick="editDialog.hide()" type="button" />
                </h:panelGrid>
                
            </h:form>
        </p:dialog>
        
        <p:confirmDialog id="deleteDialog" widgetVar="deleteDialog" message="#{messages.label_delete_record}" showEffect="fade" hideEffect="explode" header="#{messages.label_confirm_deletion}" severity="alarm">
            <h:form id="deleteForm">
                <p:commandButton value="#{messages.label_yes}" action="#{purchasesBean.deletePurchase}" update=":saveDialog :editDialog :listForm:data" oncomplete="deleteDialog.hide()" />
                <p:commandButton value="#{messages.label_no}" onclick="deleteDialog.hide()" type="button" />
            </h:form>
        </p:confirmDialog>
    </ui:define>
</ui:composition>
</html>